<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="110px"
    >
      <el-form-item label="优惠券名称" prop="lableName">
        <el-input
          v-model="queryParams.lableName"
          placeholder="请输入优惠券名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="发放对象 ALL为全部客户，若指定对象，符合条件的客户可在领券区看到 ，取客户等级代码，以逗号分隔" prop="grantCust">
        <el-input
          v-model="queryParams.grantCust"
          placeholder="请输入发放对象 ALL为全部客户，若指定对象，符合条件的客户可在领券区看到 ，取客户等级代码，以逗号分隔"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="有效期起始时间" prop="startDt">
        <!-- <el-input
          v-model="queryParams.startDt"
          placeholder="请输入有效期起始时间"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-date-picker
          v-model="queryParams.startDt"
          type="date"
          placeholder="请选择有效期起始时间"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          style="width: 215px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="有效期结束时间" prop="closeDt">
        <!-- <el-input
          v-model="queryParams.closeDt"
          placeholder="请输入有效期结束时间"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-date-picker
          v-model="queryParams.closeDt"
          type="date"
          placeholder="请选择有效期结束时间"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          style="width: 215px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="每人限领张数" prop="limitedCnt">
        <el-input
          v-model="queryParams.limitedCnt"
          placeholder="请输入每人限领张数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="描述" prop="description">
        <el-input
          v-model="queryParams.description"
          placeholder="请输入描述"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="消费达到该金额大于等于该金额可使用优惠券" prop="usedAmount">
        <el-input
          v-model="queryParams.usedAmount"
          placeholder="请输入消费达到该金额大于等于该金额可使用优惠券"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="发行数量" prop="publishCnt">
        <el-input
          v-model="queryParams.publishCnt"
          placeholder="请输入发行数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="剩余数量" prop="unclaimedCnt">
        <el-input
          v-model="queryParams.unclaimedCnt"
          placeholder="请输入剩余数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="已使用数量" prop="usedCnt">
        <el-input
          v-model="queryParams.usedCnt"
          placeholder="请输入已使用数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="抵扣金额 COUPON_TYPE = 2" prop="safetyAmount">
        <el-input
          v-model="queryParams.safetyAmount"
          placeholder="请输入抵扣金额 COUPON_TYPE = 2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="折扣  COUPON_TYPE =3" prop="discountAmount">
        <el-input
          v-model="queryParams.discountAmount"
          placeholder="请输入折扣  COUPON_TYPE =3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="优惠券发放 URL" prop="grantUrl">
        <el-input
          v-model="queryParams.grantUrl"
          placeholder="请输入优惠券发放 URL"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="优惠券图片" prop="imageUrl">
        <el-input
          v-model="queryParams.imageUrl"
          placeholder="请输入优惠券图片"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="循环使用 " prop="loopUse">
        <!-- <el-input
          v-model="queryParams.loopUse"
          placeholder="请输入循环使用 0 否 1 是 ， 【若设定为1且 USED_AMOUNT 金额大于0，每满 USED_AMOUNT 金额可使用一张，否则无论订单金额多少均只能使用一张】例如 50可使用，100既可使用 2 张"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select
          v-model="queryParams.loopUse"
          clearable
          placeholder="请选择"
          @keyup.enter.native="handleQuery"
          style="width: 215px"
        >
          <el-option
            v-for="dict in dict.type.yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="活动混用" prop="campaignUse">
        <!-- <el-input
          v-model="queryParams.campaignUse"
          placeholder="请输入活动混用 0 否 1 是 【0 若购买时已参加活动则不能使用 1 可使用】"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select
          v-model="queryParams.campaignUse"
          clearable
          placeholder="请选择"
          @keyup.enter.native="handleQuery"
          style="width: 215px"
        >
          <el-option
            v-for="dict in dict.type.yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="使用会员级别,ALL,默认持有券的客户均可使用，否则依据当前会员等级判断,BAS_CUST.CUST_TYPE,取客户等级代码，以逗号分隔" prop="usedCustlv">
        <el-input
          v-model="queryParams.usedCustlv"
          placeholder="请输入使用会员级别,ALL,默认持有券的客户均可使用，否则依据当前会员等级判断,BAS_CUST.CUST_TYPE,取客户等级代码，以逗号分隔"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="有效天数" prop="effectDay">
        <el-input
          v-model="queryParams.effectDay"
          placeholder="请输入有效天数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="使用场景" prop="useScene">
        <!-- <el-input
          v-model="queryParams.useScene"
          placeholder="请输入使用场景 【0 全场景 1 线上 2 到店】"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select
          v-model="queryParams.useScene"
          clearable
          placeholder="请选择"
          @keyup.enter.native="handleQuery"
          style="width: 215px"
        >
          <el-option
            v-for="dict in dict.type.use_scene"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="创建时间" prop="createDt">
        <el-input
          v-model="queryParams.createDt"
          placeholder="请输入创建时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="updateDt">
        <el-input
          v-model="queryParams.updateDt"
          placeholder="请输入创建时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="数据更新版本" prop="version">
        <el-input
          v-model="queryParams.version"
          placeholder="请输入数据更新版本"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账套号" prop="sysAccount">
        <el-input
          v-model="queryParams.sysAccount"
          placeholder="请输入账套号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['api:coupon:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['api:coupon:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['api:coupon:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['api:coupon:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="couponList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="主键id"
        align="center"
        prop="id"
        min-width="120"
        show-overflow-tooltip
      />
      <el-table-column
        label="优惠券名称"
        align="center"
        prop="lableName"
        min-width="120"
        show-overflow-tooltip
      />
      <el-table-column
        label="优惠券类型"
        align="center"
        prop="couponType"
        min-width="100"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.coupon_type"
            :value="scope.row.couponType"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="发放对象"
        align="center"
        prop="grantCust"
        min-width="120"
        show-overflow-tooltip
      />
      <el-table-column
        label="有效期起始时间"
        align="center"
        prop="startDt"
        min-width="140"
      />
      <el-table-column
        label="有效期结束时间"
        align="center"
        prop="closeDt"
        min-width="140"
      />
      <el-table-column
        label="每人限领张数"
        align="center"
        prop="limitedCnt"
        min-width="120"
      />
      <el-table-column
        label="描述"
        align="center"
        prop="description"
        min-width="120"
        show-overflow-tooltip
      />
      <el-table-column
        label="最低消费金额"
        align="center"
        prop="usedAmount"
        min-width="120"
      />
      <el-table-column
        label="发行数量"
        align="center"
        prop="publishCnt"
        min-width="100"
      />
      <el-table-column
        label="剩余数量"
        align="center"
        prop="unclaimedCnt"
        min-width="100"
      />
      <el-table-column
        label="已使用数量"
        align="center"
        prop="usedCnt"
        min-width="100"
      />
      <el-table-column
        label="抵扣金额"
        align="center"
        prop="safetyAmount"
        min-width="100"
      />
      <el-table-column
        label="折扣"
        align="center"
        prop="discountAmount"
        min-width="100"
      />
      <el-table-column
        label="优惠券发放"
        align="center"
        prop="grantUrl"
        min-width="100"
      />
      <el-table-column
        label="优惠券图片"
        align="center"
        prop="imageUrl"
        min-width="120"
      >
        <template slot-scope="scope">
          <div>
            <el-image
              style="width: 50px; height: 50px; border-radius: 50%"
              :src="scope.row.imageUrl"
              :preview-src-list="[scope.row.imageUrl]"
              fit="cover"
              preview-teleported="true"
            />
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="是否启用"
        align="center"
        prop="status"
        min-width="100"
      >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yes_no" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column
        label="循环使用"
        align="center"
        prop="loopUse"
        min-width="100"
      >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yes_no" :value="scope.row.loopUse" />
        </template>
      </el-table-column>
      <el-table-column
        label="活动混用"
        align="center"
        prop="campaignUse"
        min-width="100"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.yes_no"
            :value="scope.row.campaignUse"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="发放方式"
        align="center"
        prop="pubType"
        min-width="100"
      >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pub_type" :value="scope.row.pubType" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="使用会员级别,ALL,默认持有券的客户均可使用，否则依据当前会员等级判断,BAS_CUST.CUST_TYPE,取客户等级代码，以逗号分隔" align="center" prop="usedCustlv" /> -->
      <el-table-column
        label="有效天数"
        align="center"
        prop="effectDay"
        min-width="100"
      />
      <!-- <el-table-column label="计时方式 【1 根据优惠券设定的起止日期 2 客户领券时，领取日期加上有效天数作为到期日期】" align="center" prop="timeType" /> -->
      <el-table-column
        label="使用场景"
        align="center"
        prop="useScene"
        min-width="100"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.use_scene"
            :value="scope.row.useScene"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="创建时间"
        align="center"
        prop="createDt"
        min-width="160"
      />
      <el-table-column
        label="更新时间"
        align="center"
        prop="updateDt"
        min-width="160"
      />
      <!-- <el-table-column label="数据更新版本" align="center" prop="version" /> -->
      <!-- <el-table-column label="账套号" align="center" prop="sysAccount" /> -->
      <el-table-column
        label="备注"
        align="center"
        prop="remark"
        min-width="160"
        show-overflow-tooltip
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
        min-width="120"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['api:coupon:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['api:coupon:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改优惠券规则管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="优惠券名称" prop="lableName">
          <el-input v-model="form.lableName" placeholder="请输入优惠券名称" />
        </el-form-item>
        <!-- <el-form-item label="发放对象 ALL为全部客户，若指定对象，符合条件的客户可在领券区看到 ，取客户等级代码，以逗号分隔" prop="grantCust">
          <el-input v-model="form.grantCust" placeholder="请输入发放对象 ALL为全部客户，若指定对象，符合条件的客户可在领券区看到 ，取客户等级代码，以逗号分隔" />
        </el-form-item> -->
        <el-form-item label="有效期起始时间" prop="startDt">
          <!-- <el-input v-model="form.startDt" placeholder="请输入有效期起始时间" /> -->
          <el-date-picker
            v-model="form.startDt"
            type="date"
            placeholder="请选择有效期结束时间"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            style="width: 100%"
          />
        </el-form-item>
        <el-form-item label="有效期结束时间" prop="closeDt">
          <!-- <el-input v-model="form.closeDt" placeholder="请输入有效期结束时间" /> -->
          <el-date-picker
            v-model="form.closeDt"
            type="date"
            placeholder="请选择有效期结束时间"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            style="width: 100%"
          />
        </el-form-item>
        <el-form-item label="每人限领张数" prop="limitedCnt">
          <el-input
            v-model="form.limitedCnt"
            placeholder="请输入每人限领张数"
          />
        </el-form-item>
        <el-form-item label="描述" prop="description">
          <el-input v-model="form.description" placeholder="请输入描述" />
        </el-form-item>
        <el-form-item label="最低消费金额" prop="usedAmount">
          <el-input
            v-model="form.usedAmount"
            placeholder="请输入消费达到该金额大于等于该金额可使用优惠券"
          />
        </el-form-item>
        <el-form-item label="发行数量" prop="publishCnt">
          <el-input v-model="form.publishCnt" placeholder="请输入发行数量" />
        </el-form-item>
        <el-form-item label="剩余数量" prop="unclaimedCnt">
          <el-input v-model="form.unclaimedCnt" placeholder="请输入剩余数量" />
        </el-form-item>
        <el-form-item label="已使用数量" prop="usedCnt">
          <el-input v-model="form.usedCnt" placeholder="请输入已使用数量" />
        </el-form-item>
        <el-form-item label="抵扣金额" prop="safetyAmount">
          <el-input v-model="form.safetyAmount" placeholder="请输入抵扣金额" />
        </el-form-item>
        <el-form-item label="折扣" prop="discountAmount">
          <el-input v-model="form.discountAmount" placeholder="请输入折扣" />
        </el-form-item>
        <el-form-item label="优惠券发放" prop="grantUrl">
          <el-input v-model="form.grantUrl" placeholder="请输入优惠券发放" />
        </el-form-item>
        <el-form-item label="优惠券图片" prop="imageUrl">
          <!-- <el-input v-model="form.imageUrl" placeholder="请输入优惠券图片" /> -->
          <ImageUpload :limit="1" v-model="form.imageUrl" />
        </el-form-item>
        <el-form-item label="循环使用" prop="loopUse">
          <!-- <el-input v-model="form.loopUse" placeholder="请输入循环使用 0 否 1 是 ， 【若设定为1且 USED_AMOUNT 金额大于0，每满 USED_AMOUNT 金额可使用一张，否则无论订单金额多少均只能使用一张】例如 50可使用，100既可使用 2 张" /> -->
          <el-select
            v-model="form.loopUse"
            clearable
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option
              v-for="dict in dict.type.yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="活动混用" prop="campaignUse">
          <!-- <el-input v-model="form.campaignUse" placeholder="请输入活动混用 0 否 1 是 【0 若购买时已参加活动则不能使用 1 可使用】" /> -->
          <el-select
            v-model="form.campaignUse"
            clearable
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option
              v-for="dict in dict.type.yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            />
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="使用会员级别,ALL,默认持有券的客户均可使用，否则依据当前会员等级判断,BAS_CUST.CUST_TYPE,取客户等级代码，以逗号分隔" prop="usedCustlv">
          <el-input v-model="form.usedCustlv" placeholder="请输入使用会员级别,ALL,默认持有券的客户均可使用，否则依据当前会员等级判断,BAS_CUST.CUST_TYPE,取客户等级代码，以逗号分隔" />
        </el-form-item> -->
        <el-form-item label="有效天数" prop="effectDay">
          <el-input v-model="form.effectDay" placeholder="请输入有效天数" />
        </el-form-item>
        <el-form-item label="使用场景" prop="useScene">
          <!-- <el-input v-model="form.useScene" placeholder="请输入使用场景 【0 全场景 1 线上 2 到店】" /> -->
          <el-select
            v-model="form.useScene"
            clearable
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option
              v-for="dict in dict.type.use_scene"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            />
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="创建时间" prop="createDt">
          <el-input v-model="form.createDt" placeholder="请输入创建时间" />
        </el-form-item>
        <el-form-item label="创建时间" prop="updateDt">
          <el-input v-model="form.updateDt" placeholder="请输入创建时间" />
        </el-form-item>
        <el-form-item label="数据更新版本" prop="version">
          <el-input v-model="form.version" placeholder="请输入数据更新版本" />
        </el-form-item>
        <el-form-item label="账套号" prop="sysAccount">
          <el-input v-model="form.sysAccount" placeholder="请输入账套号" />
        </el-form-item> -->
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listCoupon,
  getCoupon,
  delCoupon,
  addCoupon,
  updateCoupon,
} from "@/api/djk/cardMgr/coupon";

export default {
  name: "Coupon",
  dicts: ["sys_enabled", "yes_no", "use_scene", "coupon_type", "pub_type"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 优惠券规则管理表格数据
      couponList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        lableName: null,
        couponType: null,
        grantCust: null,
        startDt: null,
        closeDt: null,
        limitedCnt: null,
        description: null,
        usedAmount: null,
        publishCnt: null,
        unclaimedCnt: null,
        usedCnt: null,
        safetyAmount: null,
        discountAmount: null,
        grantUrl: null,
        imageUrl: null,
        status: null,
        loopUse: null,
        campaignUse: null,
        pubType: null,
        usedCustlv: null,
        effectDay: null,
        timeType: null,
        useScene: null,
        createDt: null,
        updateDt: null,
        version: null,
        sysAccount: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        useScene: [
          {
            required: true,
            message: "使用场景不能为空",
            trigger: "change",
          },
        ],
        // createDt: [
        //   { required: true, message: "创建时间不能为空", trigger: "blur" },
        // ],
        // updateDt: [
        //   { required: true, message: "创建时间不能为空", trigger: "blur" },
        // ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询优惠券规则管理列表 */
    getList() {
      this.loading = true;
      listCoupon(this.queryParams).then((response) => {
        this.couponList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        lableName: null,
        couponType: null,
        grantCust: null,
        startDt: null,
        closeDt: null,
        limitedCnt: null,
        description: null,
        usedAmount: null,
        publishCnt: null,
        unclaimedCnt: null,
        usedCnt: null,
        safetyAmount: null,
        discountAmount: null,
        grantUrl: null,
        imageUrl: null,
        status: null,
        loopUse: null,
        campaignUse: null,
        pubType: null,
        usedCustlv: null,
        effectDay: null,
        timeType: null,
        useScene: null,
        createDt: null,
        updateDt: null,
        version: null,
        sysAccount: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加优惠券规则管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getCoupon(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改优惠券规则管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateCoupon(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCoupon(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除优惠券规则管理编号为"' + ids + '"的数据项？')
        .then(function () {
          return delCoupon(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "api/coupon/export",
        {
          ...this.queryParams,
        },
        `coupon_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
